import { isFn } from './isFn'
import { isObj } from './isObj'
import { isArr } from './isArr'
import { optimizeCb } from './optimizeCb'
import { matcher } from './matcher'
import { property } from './property'
// 10137
/**
 * 创建回调函数，内部模块使用
 * dependencies isFn isObj isArr optimizeCb matcher identity types property
 * @param {*} val 
 * @param {*} ctx 
 * @param {*} argCount 参数个数number
 * @returns 
 */
export function safeCb (val, ctx, argCount) {
  
  if (val == null) {
    return val;
  }
  if (isFn(val)) {
    return optimizeCb(val, ctx, argCount);
  }
  if (isObj(val) && !isArr(val)) {
    return matcher(val);
  }

  return property(val);
}

